package com.HuiShou.controller.common;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.HuiShou.common.annotation.Log;
import com.HuiShou.common.core.controller.BaseController;
import com.HuiShou.common.core.domain.AjaxResult;
import com.HuiShou.common.enums.BusinessType;
import com.HuiShou.domain.PointsExchangeRecord;
import com.HuiShou.service.IPointsExchangeRecordService;
import com.HuiShou.common.utils.poi.ExcelUtil;
import com.HuiShou.common.core.page.TableDataInfo;

/**
 * 积分兑换记录Controller
 * 
 * @author lyz
 * @date 2025-03-21
 */
@RestController
@RequestMapping("/mall/record")
public class PointsExchangeRecordController extends BaseController
{
    @Autowired
    private IPointsExchangeRecordService pointsExchangeRecordService;

    /**
     * 查询积分兑换记录列表
     */
    @PreAuthorize("@ss.hasPermi('mall:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(PointsExchangeRecord pointsExchangeRecord)
    {
        startPage();
        List<PointsExchangeRecord> list = pointsExchangeRecordService.selectPointsExchangeRecordList(pointsExchangeRecord);
        return getDataTable(list);
    }

    /**
     * 导出积分兑换记录列表
     */
    @PreAuthorize("@ss.hasPermi('mall:record:export')")
    @Log(title = "积分兑换记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PointsExchangeRecord pointsExchangeRecord)
    {
        List<PointsExchangeRecord> list = pointsExchangeRecordService.selectPointsExchangeRecordList(pointsExchangeRecord);
        ExcelUtil<PointsExchangeRecord> util = new ExcelUtil<PointsExchangeRecord>(PointsExchangeRecord.class);
        util.exportExcel(response, list, "积分兑换记录数据");
    }

    /**
     * 获取积分兑换记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('mall:record:query')")
    @GetMapping(value = "/{exchangeId}")
    public AjaxResult getInfo(@PathVariable("exchangeId") String exchangeId)
    {
        return success(pointsExchangeRecordService.selectPointsExchangeRecordByExchangeId(exchangeId));
    }

    /**
     * 新增积分兑换记录
     */
    @PreAuthorize("@ss.hasPermi('mall:record:add')")
    @Log(title = "积分兑换记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PointsExchangeRecord pointsExchangeRecord)
    {
        return toAjax(pointsExchangeRecordService.insertPointsExchangeRecord(pointsExchangeRecord));
    }

    /**
     * 修改积分兑换记录
     */
    @PreAuthorize("@ss.hasPermi('mall:record:edit')")
    @Log(title = "积分兑换记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PointsExchangeRecord pointsExchangeRecord)
    {
        return toAjax(pointsExchangeRecordService.updatePointsExchangeRecord(pointsExchangeRecord));
    }

    /**
     * 删除积分兑换记录
     */
    @PreAuthorize("@ss.hasPermi('mall:record:remove')")
    @Log(title = "积分兑换记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{exchangeIds}")
    public AjaxResult remove(@PathVariable String[] exchangeIds)
    {
        return toAjax(pointsExchangeRecordService.deletePointsExchangeRecordByExchangeIds(exchangeIds));
    }
}
